<section class="content-header" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="#">开发计划</a></li>
        <li class="active">开发详情</li>
    </ol>
</section>
<!-- Main content -->
<section class="content">
    <div class="jax-box">
        <form id="formSearch" class="form-horizontal form-search">
            <div class="form-group">
                <div class="col-md-4 col-sm-6">
                    <label class="control-label  col-xs-4" for="plaChcId">销售机会编号:</label>
                    <div class="col-xs-8">
                        <input type="text" class="form-control" placeholder="" id="plaChcId">
                    </div>
                </div>
                <div class="col-md-4 col-sm-6">
                    <label class="control-label  col-xs-4" for="plaResult">承担:</label>
                    <div class="col-xs-8">
                        <select name="plaResult" id="plaResult" class="form-control m-b">
                            <option  value="0">全部订单</option>
                            <option  value="1">已成订单</option>
                            <option  value="2">未成订单</option>
                        </select>
                    </div>
                </div>
                <shiro:hasPermission name="cstService:list">
                    <div class="col-md-1 col-sm-6 " style="text-align:left;">
                        <button type="button" id="btn_query" class="btn btn-info">查询</button>
                    </div>
                </shiro:hasPermission>
            </div>
        </form>
    </div>
    <div class="jax-box jax-box-table">
        <div id="toolbar" class="btn-group">
            <shiro:hasPermission name="cstService:add">
                <button id="btn_add" type="button" class="btn btn-primary" data-toggle="modal" data-target="#userModal">
                    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
                </button>
            </shiro:hasPermission>
            <shiro:hasPermission name="cstService:batchDelete">
                <button id="btn_batch_delete" type="button" class="btn btn-danger">
                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>批量删除
                </button>
            </shiro:hasPermission>
        </div>
        <table id="table"></table>
    </div>
</section>
<!-- 用户新增模态框 -->
<div id="userModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <!--        user新增按钮页面-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">新增订单</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="cstServiceForm">
                    <div class="box-body">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">销售机会编号 <span style="color: red">*</span>:</label>
                            <div class="col-sm-8">
                                <input name="plaChcId" class="form-control" require="必填项" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">计划内容 :</label>

                            <div class="col-sm-8">
                                <input name="plaTodo" class="form-control" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">执行效果 :</label>

                            <div class="col-sm-8">
                                <select name="plaResult" id="plaResult2" class="form-control m-b">
                                    <option  value="0">待成单</option>
                                    <option  value="1">已成单</option>
                                </select>
                            </div>
                        </div>

                    </div>
                    <div class="box-footer">
                        <div class="pull-right">
                            <button type="button" id="saveUser" class="btn btn-info">确定</button>
                            <button type="button" data-dismiss="modal" class="btn btn-default">取消</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!--&lt;!&ndash; 用户详情模态框 &ndash;&gt;-->
<div id="userDetailModal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">用户信息</h4>
            </div>
            <div class="modal-body">
                <div id="userOpenWindow">
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    var editFlag = "[[${@perms.hasPerm('cstService:edit')}]]";
    var deleteFlag = "[[${@perms.hasPerm('cstService:delete')}]]";
    // var assignRoleFlag = "[[${@perms.hasPerm('user:assignRole')}]]";
    var plaIdStr;//批量用户id
    var roleIdStr;//分配的角色
    // var selectRoleIds;
    var userIdChecked;
    // var loadRoleCount = 0;
    var columns = [
        {checkbox: true},
        {
            field: 'plaChcId',
            title: '销售机会编号',
            align: "center"
        },{
            field: 'plaDate',
            title: '计划时间',
            align: "center"
        }, {
            field: 'plaTodo',
            title: '计划内容',
            align: "center"
        }, {
            field: 'plaResult',
            title: '执行效果',
            align: "center",
            formatter: function (value, row, index) {
                if(row.plaResult == 1){
                    return  "已成单";
                }else {
                    return "未成单";
                }
            }
        },
        {
            field: 'plaStatus',
            title: '订单状态',
            align: "center",
            formatter: function (value, row, index) {
                return row.plaStatus == '1' ? "启用" : "禁用";
            }
        },
        {
            field: 'operation',
            title: '操作',
            align: "center",
            formatter: function (value,
                                 row, index) {
                console.log(row.plaId);
                var edit = editFlag == "true" ? '<a class="table-btn table-btn-info" href="javascript:void(0)" onclick="editUser(' + row.plaId + ')">编辑</a>' : '';
                var del = deleteFlag == "true" ? '<a  class="table-btn table-btn-danger" href="javascript:void(0)" onclick="deleteUser(' + row.plaId + ')">删除</a>' : '';
                return edit  + del;
            }
        }];
    var options = {
        id: "#table",
        url: '/cstService/list',
        columns: columns,
        toolbar: '#toolbar',
        showRefresh: true,
        queryParams: queryParams
    }
    Core.initTable(options);

    /*查询用户参数*/
    function queryParams(params) {
        var temp = { //这里的键的名字和控制器的变量名必须一致，这边改动，控制器也需要改成一样的
            limit: params.limit, //页面大小
            offset: params.offset, //页码
            // odrCustId: $("#odrCustId").val(),
            plaChcId: $("#plaChcId").val(),
            plaResult: $("#plaResult").val(),
        };
        return temp;
    }

    /*查询角色参数*/
    function queryRoleParams(params) {
        var temp = {
            plaId: userIdChecked
        };
        return temp;
    }

    // /*编辑*/
    function editUser(plaId) {
        Core.load("#userOpenWindow", "/cstService/edit?plaId=" + plaId, function () {
            $("#userDetailModal").modal("show");
        }, 2);
    }
    //
    /*删除*/
    function deleteUser(plaId) {
        Core.confirm("确定删除该用户？", function () {
            Core.postAjax("/cstService/delete", {"plaId": plaId}, function (data) {
                if (data.status == 200) {
                    Core.refreshTable("#table");
                }
                layer.msg(data.msg);
            }, "get")
        })
    }



    $(function () {
        /*查询*/
        $("#btn_query").click(function () {
            Core.refreshTable("#table");
        });
        //     /*新增*/
        $("#btn_add").click(function () {
            Core.clearError("#cstServiceForm");
        });
        /*批量删除*/
        $("#btn_batch_delete").click(function () {
            var checkedRows = Core.selectMutiData("#table");
            if (checkedRows) {
                Core.confirm("确定删除选中的" + checkedRows.length + "条记录？", function () {
                    plaIdStr = "";
                    $.each(checkedRows, function (i, item) {
                        plaIdStr += (item.plaId + ",");
                    })
                    plaIdStr = plaIdStr.substring(0, plaIdStr.length - 1);
                    Core.postAjax("/cstService/batch/delete", {"plaIdStr": plaIdStr}, function (data) {
                        if (data.status == 200) {
                            Core.refreshTable("#table");
                        }
                        layer.msg(data.msg);
                    }, "get")
                })
            }
        });

        /*保存用戶 新增 确定*/
        $("#saveUser").click(function () {
            if (doValidForm(cstServiceForm)) {
                Core.mask("#saveUser");
                Core.postAjax("/cstService/add", $("#cstServiceForm").serialize(), function (data) {
                    Core.unmask("#saveUser");
                    if (data.status == 200) {
                        $("#userModal").modal("hide");
                        $("#cstServiceForm")[0].reset();
                        Core.refreshTable("#table")
                    }
                    layer.msg(data.msg);
                })
            }
        });
    });

</script>